/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managerBeanViews;

import entity.Members;
import java.io.Serializable;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import processor.MembersFacade;

/**
 *
 * @author maynoigi
 */
@ManagedBean
@SessionScoped
public class Login implements Serializable{

    @EJB
    private MembersFacade membersFacade;

    public String getAlert() {
        return alert;
    }

    public void setAlert(String alert) {
        this.alert = alert;
    }
    private String alert = "";

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }
    private String userName = "Enter Your Username";
    private String password = "password";
    private Members customer = null;

    public Members getCustomer() {
      
        return customer;
    }

    public void setCustomer(Members customer) {
        this.customer = customer;
    }

    public Login() {
      
    }

    public String loginPage() {
        customer = membersFacade.checkLogin(userName, password);
        if (customer == null) {
            alert = "UsersName or Password is invalid";
        }
        return null;
    }
    
    public String loginAdminPage() {
        customer = membersFacade.checkLogin(userName, password);
        if (customer == null) {
            alert = "UsersName or Password is invalid";
        }else if(customer.getMembersRole() != 2){
            alert = "You have not permission administrator";
        }
        return null;
    }

    public String logout() {
        customer = null;
        userName = "Enter Your Username";
        alert="";
        return "index.xhtml";
        
    }
}
